﻿using System;
using System.Threading.Tasks;
using TimServerSDK.Core;
using TimServerSDK.Core.Enums;
using TimServerSDK.Friends.Dtos;

namespace TimServerSDK.Friends
{
    public class FriendTimServerApi : AbstractTimServerApi, IFriendTimServerApi
    {
        protected override string ServiceName { get; } = "sns";

        public FriendTimServerApi(IRestClientProvider restClientProvider) : base(restClientProvider)
        {
        }

        public Task<TimServerResult> AddAsync(string fromAccount, AddFriendItemDto[] addFriendItem, TimServerFriendAddType addType = TimServerFriendAddType.Add_Type_Both, int forceAddFlags = 0)
        {
            return PostAsync<TimServerResult>("friend_add", new
            {
                From_Account = fromAccount,
                AddFriendItem = addFriendItem,
                AddType = addType.ToString(),
                ForceAddFlags = forceAddFlags
            });
        }

        public Task<TimServerResult> DeleteAsync(string fromAccount, string[] toAccount, TimServerFriendDeleteType deleteType = TimServerFriendDeleteType.Delete_Type_Both)
        {
            return PostAsync<TimServerResult>("friend_delete", new
            {
                From_Account = fromAccount,
                To_Account = toAccount,
                DeleteType = deleteType.ToString()
            });
        }

        public Task<GetFriendResultDto> GetAsync(string fromAccount, int startIndex, int? standardSequence = null, int? customSequence = null)
        {
            return PostAsync<GetFriendResultDto>("friend_get", new
            {
                From_Account = fromAccount,
                StartIndex = startIndex,
                StandardSequence = standardSequence,
                CustomSequence = customSequence
            });
        }
    }
}
